package com.eshop.service.impl.mongodb;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.eshop.dao.mongodb.SmokeCertDao;
import com.eshop.frameworks.core.dao.DAO;
import com.eshop.frameworks.core.entity.PageEntity;
import com.eshop.frameworks.core.service.impl.AbstractService;
import com.eshop.model.mongodb.SmokeCert;
import com.eshop.service.mongodb.SmokeCertService;

@Service("smokeCertService")
public class SmokeCertServiceImpl extends AbstractService<SmokeCert, String> implements SmokeCertService {
	@Autowired
	private SmokeCertDao smokeCertDao;

	@Override
	public DAO<SmokeCert, String> getDao() {
		return smokeCertDao;
	}

	@Override
	public SmokeCert findByUserId(String userId) {
		return getDao().findOne(new Query(Criteria.where("userId").is(userId)), SmokeCert.class);
	}

	@Override
	public List<SmokeCert> findList(PageEntity page) {
		Query query = new Query();
		List<Order> orders = new ArrayList<Order>();
		orders.add(new Order(Direction.ASC,"status"));
		orders.add(new Order(Direction.DESC,"createTime"));
		query.with(new Sort(orders));
		query.skip(page.getStartRow()).limit(page.getPageSize());
		return getDao().findList(query, SmokeCert.class);
	}

	

}
